//
//  VideoGenerateTitleCell.swift
//  NDAi
//
//  Created by 丸子 on 2024/6/21.
//

import UIKit
import YYText
class VideoGenerateTitleCell: UITableViewCell, YYTextViewDelegate {
    var chooseDesc:((String) -> Void)?

    lazy var lineView: UIView = {
        let view = UIView()
        view.backgroundColor = Theme.color.main
        view.allRound(3)
        return view
    }()
    lazy var titleLb: UILabel = {
        let label = UILabel()
        label.font = UIFont.pingFangSCRegular(ofSize: 15)
        label.textColor = Theme.color.main
        label.text = "输入主题"
        return label
    }()
    
    lazy var descView: UIView = {
        let view = UIView()
        view.allRound(8)
        view.backgroundColor = .white
        return view
    }()
    
    lazy var descTextView: YYTextView = {
        let view = YYTextView()
        view.textContainerInset = UIEdgeInsets(top: 15, left: 15, bottom: 15, right: 15);
        view.placeholderText = "请输入你想要的短视频主题，如“狐仙与道士"
        view.placeholderFont = UIFont.pingFangSCRegular(ofSize: 12)
        view.placeholderTextColor = Theme.color.text_d3
        view.textColor = Theme.color.text_d1
        view.delegate = self
        view.font = UIFont.pingFangSCRegular(ofSize: 12)
        return view
    }()
    
    override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) {
        super.init(style: style, reuseIdentifier: reuseIdentifier)
        backgroundColor = .clear
        selectionStyle = .none
        contentView.addSubviews([lineView, titleLb, descView])
        descView.addSubviews([descTextView])
 
        lineView.snp.makeConstraints { make in
            make.top.equalTo(22)
            make.leading.equalTo(16)
            make.height.equalTo(16)
            make.width.equalTo(6)
        }
        
        titleLb.snp.makeConstraints { make in
            make.centerY.equalTo(lineView)
            make.leading.equalTo(lineView.snp.trailing).offset(8)
        }
        
        descView.snp.makeConstraints { make in
            make.top.equalTo(lineView.snp.bottom).offset(12)
            make.leading.trailing.equalToSuperview().inset(16)
            make.height.equalTo(GET_WIDTH(W: 80))
        }
        
        descTextView.snp.makeConstraints { make in
            make.edges.equalToSuperview()
        }
    }
    
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    
    func textViewDidChange(_ textView: YYTextView) {
        let currentLength = textView.text.count
        if textView == self.descTextView {
            if currentLength > 255 {
                textView.text = String(textView.text.prefix(255))
            }
            self.chooseDesc?(textView.text)
        } else {
            if currentLength > 50 {
                textView.text = String(textView.text.prefix(50))
            }
            
        }
    }
    func textViewDidEndEditing(_ textView: YYTextView) {
         
    }
   

}
